package arithmetic.leetCode.yi;

import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: yilin
 * Date: 2019-07-15
 * Time: 18:30
 */
public class StringSort {

    public static void main(String[] args) {
        System.out.println(checkInclusion("ab", "eidbaooo"));
    }

    public static boolean checkInclusion(String s1, String s2) {
        int length = s1.length();
        int lenght2 = s2.length();
        int c1[] = new int[26];
        int c2[] = new int[26];
        for (char chars : s1.toCharArray()) {
            c1[chars - 'a']++;
        }
        for (int i = 0; i < lenght2; i++) {
            if (i >= length) {
                --c2[s2.charAt(i - length) - 'a'];
            }
            c2[s2.charAt(i) - 'a']++;
            if (Arrays.equals(c1, c2)) {
                return true;
            }
        }

        return false;
    }
}
